#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import utils.rand_kit as rand_kit

def findSmalllest(arr):
    smallest = arr[0]
    smallest_index = 0
    for i in range(1, len(arr)):
        if arr[i] < smallest:
            smallest = arr[i]
            smallest_index = i
    return smallest_index

# 选择排序，复杂度O(n^2)
def selectionSort(arr):
    newArr = []
    for i in range(len(arr)):
        smalllest = findSmalllest(arr)
        newArr.append(arr.pop(smalllest))
    return newArr

if __name__ == "__main__":
    arr = rand_kit.rand_arr()
    print(selectionSort(arr))